package com.youlu.campus.web.form;
import com.youlu.campus.entity.form.UserFormTaskInfo;
import com.youlu.campus.service.form.UserFormTaskInfoService;
import com.youlu.campus.web.common.base.RequestContext;
import com.yuelin.infrastructure.quantum.common.QResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 用户表单控制器
 */
@RestController
public class UserFormController {
    @Autowired
    private UserFormTaskInfoService userFormTaskInfoService;

    @PostMapping("/mini-app/form/user/create")
    public QResult create(@RequestBody UserFormTaskInfo req) {
        req.setUserId(RequestContext.getUserId());
        req.setAppId(RequestContext.getAppId());
        req.setOpenId(RequestContext.getCurUser().getOpenId());
        req.setPlatform(RequestContext.getCurPlatform());
        return QResult.success(userFormTaskInfoService.create(req));
    }

    @PostMapping("/mini-app/form/user/update")
    public QResult update(@RequestBody UserFormTaskInfo req) {
        return QResult.success(userFormTaskInfoService.update(req));
    }

    @GetMapping("/mini-app/form/user/find")
    public QResult find(@RequestParam("formId") String formId) {
        return QResult.success(userFormTaskInfoService.findBy(RequestContext.getUserId(), formId));
    }
}
